<div class="main_container">
	<div class="main_label_header_container">
		<h2><?php echo $page_label; ?></h2>
	</div>
	<br/>
	<div class="form-wrapper">
		<?php if (validation_errors()): ?>
		<div class="error-box">
			<?php echo validation_errors('<div>','</div>');?>
		</div>
		<?php endif; ?>
		
		<?php echo form_open(site_url('transaction/registration/register')); ?>
		<div class="category-container">
			<h2>Customer Information</h2>
		</div>
		<label for="registration_number"><?php echo lang('registration_label_reg_num'); ?></label>
		<input type="text" maxlength="10" autocomplete="off" class="ipt-txt half-width" name="number" readonly="readonly" value="<?php echo $invoice_number; ?>" />
		<br/>
		<label for="registration_customer"><?php echo lang('registration_label_customer'); ?></label>
		<input type="text" maxlength="30" autocomplete="off" class="ipt-txt full-width" id="customer_id" value="<?php echo set_value('customer_id)');?>" />
		<input type='hidden' name='customer_id' id="hidden_cust_id" />
		<br/>
		<label for="registration_memo"><?php echo lang('registration_label_memo'); ?></label>
		<input type="text" maxlength="30" autocomplete="off" class="ipt-txt full-width" name="memo" value="<?php echo set_value('memo');?>" />
		<div class="category-container">
			<h2>Contact Information</h2>
		</div>
		<label for="registration_customer_phone"><?php echo lang('registration_label_phone'); ?></label>
		<input type="text" maxlength="30" autocomplete="off" class="ipt-txt full-width" name="phone" value="<?php echo set_value('phone');?>" />
		<br/>
		<label for="registration_customer_mobile"><?php echo lang('registration_label_mobile'); ?></label>
		<input type="text" maxlength="30" autocomplete="off" class="ipt-txt full-width" name="mobile" value="<?php echo set_value('mobile');?>" />
		<br/>
		<label for="registration_customer_email"><?php echo lang('registration_label_email'); ?></label>
		<input type="text" maxlength="30" autocomplete="off" class="ipt-txt full-width" name="email" value="<?php echo set_value('email');?>" />
		<br/>
		<ul class="tabs">
			<li><a href="#tab1">Particulars</a></li>
		</ul>
		<div class="tab_container">
			<div id="tab1" class="tab_content">
				<table class="table-grid" id="invoice-grid">
					<thead>
						<tr>
							<th><?php echo lang('registration_particular_item'); ?></th>
							<th><?php echo lang('registration_particular_quantity'); ?></th>
							<th><?php echo lang('registration_particular_term'); ?></th>
							<th><?php echo lang('registration_particular_rate'); ?></th>
							<th><?php echo lang('registration_particular_amount'); ?></th>
							<th class="action-width"></th>
						</tr>
					</thead>
					<tbody>
						<tr>
							<td><input type="text" autocomplete="off" class="item_listings" value="<?php echo set_value('address1');?>" size="25" />
								<input type='hidden' class="item_id_hidden" name="item_id[]" /></td>
							<td><input type="text" autocomplete="off" class="item_quantity" name="quantity[]" value="<?php echo set_value('address2');?>" size="25" /></td>
							<td><input type="text" autocomplete="off" class="item_term" name="term[]" value="<?php echo set_value('city');?>" size="25" /></td>
							<td><input type="text" autocomplete="off" class="item_rate" name="rate[]" value="<?php echo set_value('province');?>" size="25" /></td>
							<td><input type="text" autocomplete="off" class="item_amount" name="amount[]" value="<?php echo set_value('zip');?>" size="25" /></td>
							<td class="align-center"></td>
						</tr>
					</tbody>
					<tfoot>
						<tr>
							<td colspan="5"></td>
							<td class="align-center"><a href="#" class="btn btn-add"><span class="btn-icon plus-icon"></span><?php echo lang('registration_button_create'); ?></a></td>
						</tr>
					</tfoot>
				</table>
			</div>
		</div>
		<fieldset id="action">
		<a href="#" class="btn btn-save"><span class="btn-icon disk-icon"></span><?php echo lang('registration_button_save'); ?></a>
		<a href="<?php echo site_url('student/student'); ?>" class="btn btn-cancel"><span class="btn-icon cancel-icon"></span><?php echo lang('registration_button_cancel'); ?></a>
		</fieldset>
		<?php echo form_close(); ?>
	</div>
</div>
<script type="text/javascript">
	$('.btn-save').click(function() {
		$('form').submit();
		return false;
	});
	
	$("#customer_id").tokenInput("<?php echo site_url('student/student/get_student'); ?>", {
		hintText: "Student Name/Number",
		noResultsText: "No Match Found",
		searchingText: "Searching...",
		tokenLimit:1,
		preventDuplicates:true,
		idPrefix: 'token-listing-',
		onAdd:function(data) {
			$('#customer_id').val(data.id);
			
			$('#customer_id').change(function() {
				$('#hidden_cust_id').val(data.id);
			});
		},
		onDelete:function(){
			$('#customer_id').val('');
		}
		
    });
	
	$('.item_listings').tokenInput("<?php echo site_url('student/student/get_items'); ?>", {
		hintText: "Items",
		noResultsText: "No Match Found",
		searchingText: "Searching...",
		tokenLimit:1,
		preventDuplicates:true,
		idPrefix:'tokenn',
		onAdd:function(data){
			$(this).next('.item_id_hidden').val(data.id);
		},
		onDelete:function(){
			$(this).next('.item_id_hidden').val('');
			$(this).parent().siblings().find('.item_quantity').val('');
			$(this).parent().siblings().find('.item_rate').val('');
			$(this).parent().siblings().find('.item_term').val('');
			$(this).parent().siblings().find('.item_amount').val('');
		}
	});
	var counter = 0;
	$('.btn-add').click(function(){
		$('#invoice-grid tbody').append(
			$('<tr>').append(
				$('<td>').append(
					$('<input type="text">').addClass('item_listings').attr({'id':'item_selector'+counter}),
					$('<input type="hidden">').addClass('item_id_hidden').attr({'id':'item_id_'+counter, 'name':'item_id[]'})
				),
				$('<td>').append(
					$('<input type="text">').addClass('item_quantity').attr({'id':'quantity_'+counter,'autocomplete':'off','name':'quantity[]'})
				),
				$('<td>').append(
					$('<input type="text">').attr({'id':'term_'+counter,'autocomplete':'off','name':'term[]'})
				),
				$('<td>').append(
					$('<input type="text">').attr({'id':'rate_'+counter,'autocomplete':'off','name':'rate[]'})
				),
				$('<td>').append(
					$('<input type="text">').attr({'id':'amout_'+counter,'autocomplete':'off','name':'amount[]'})
				),
				$('<td>').append(
					$('<a>').attr({'href':'#','class':'btn btn-delete'}).append(
						$('<span>').addClass('btn-icon delete-icon')
					).bind('click',function(){
						$(this).parent().parent().remove();
					})
				)
			)
		);
		
		$('#item_selector'+counter).attr('rel',counter).tokenInput("<?php echo site_url('student/student/get_items'); ?>", {
			hintText: "Items",
			noResultsText: "No Match Found",
			searchingText: "Searching...",
			tokenLimit:1,
			preventDuplicates:true,
			idPrefix:'tokenn',
			onAdd:function(data){
				$('#item_id_'+counter).val(data.id);
			},
			onDelete:function(){
				$('#item_id_'+$(this).attr('rel')).val('');
				$('#term_'+$(this).attr('rel')).val('');
				$('#rate_'+$(this).attr('rel')).val('');
				$('#quantity_'+$(this).attr('rel')).val('');
				$('#amout_'+$(this).attr('rel')).val('');
			}
		});
		
		counter++;
	});

</script>